home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11587 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointers to structures question.
  5. Date: 25 Mar 1996 11:28:49 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4j601h$btp@sparcserver.lrz-muenchen.de>
  9. References: <4j2drs$q3r@dfw-ixnews3.ix.netcom.com> <3154F14C.35ED@ix.netcom.com>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. Brian Land <bland@ix.netcom.com> writes:
  13.  
  14. >Andrew Heiz wrote:
  15. >> 
  16. >> Hi there,
  17. >> 
  18. >> Thanks for reading.
  19. >> 
  20. >> I have a simple question about using pointers to structures. I am
  21. >> imputing data into a structure using:
  22. >> 
  23. >>         gets(struct.element);
  24. >> 
  25. >> My question is in how to reference the structure element with a
  26. >> pointer. How do I do this?
  27. >> 
  28.  
  29.  
  30. >How about....
  31.  
  32. >          gets( &(struct.element) );
  33.  
  34. If "struct.element" is something that is worth being passed to gets()
  35.  - or fgets() for programmers who want to get input from anything but
  36. another program with well-defined behaviour - then "gets(struct.element)"
  37. passes a pointer to char whereas "gets(&struct.element)" passes either a
  38. pointer to an array of char or a pointer to a pointer to char. Check what 
  39. _your_ gets() expects. If it does not expect a pointer to char, talk to 
  40. the vendor of your standard C library.
  41.  
  42. Andrew's question cannot be answered without assuming something about
  43. what he is talking about. It is hard but not impossible to think of
  44. a situation where the "&" operator might be necessary.
  45.  
  46. Kurt
  47. -- 
  48. | Kurt Watzka                             Phone : +49-89-2180-6254
  49. | watzka@stat.uni-muenchen.de
  50. | ua302aa@sunmail.lrz-muenchen.de
  51.